<?php
$version = Zend_Registry::get('version');
$global_conf = Zend_Registry::get('global_conf');
$currency = new Zend_Currency($global_conf['default_locale']);
$logo = '';
if($this->logo != '')
{ 
	$logo = '<span class="thumb"><img src="data/frontImages/gateway/gateway_logo/'.$this->logo.'" width="45" height="35" /></span>';
}
?>

<script type="text/javascript">
$(document).ready(function() {	
	floatingbar('#floatingbar',"#button_top_bar",null);
	 imageThumbnil();
	function openMsgDialog(msg)
	{
		$('#dialog_msg').html(msg).dialog({
			autoOpen: true,
			modal: true,
			show: 'fade',
			resizable: 'false',				
			buttons: { "<?php echo html_entity_decode($this->translator->translator('common_ok'), ENT_QUOTES, 'UTF-8'); ?>": function() { $(this).dialog('option', 'hide', 'explode').dialog("close"); } },
			open: function(event, ui)
				 {
					setTimeout(function() 
					{									
						if($('#' + event.target.id).dialog('isOpen'))
						{
							$('#' + event.target.id).dialog('option', 'hide', 'explode').dialog('close');										
						}
					}, 10000);
				  }
		});
	}
	
	$("#upload-form").dialog({
		autoOpen: false,
		width: 570,
		height: 480,
		show: 'fade',			
		modal: true
	});	
	
	$('a.upload_btn').click(function() {
		var self = this;
				
		$("#i-upload-form").attr("src", "<?php echo $this->url( array('module' => 'Paymentgateway','controller' => 'backendgateway', 'action'     => 'uploadfile' ), 'adminrout',    true); ?>");			
		$('#upload-form').dialog('open');
	});	
	
	$('a.select_file_btn').click(function() {		 
			var currentIFrame = $('#i-upload-form');
			var v = currentIFrame.contents().find("#file_name").val();
			if(v == '' || v == null)
			{
				var msg = "<?php echo $this->translator->translator('insert_selected_file_err'); ?>";				
				openMsgDialog(msg);
			}
			else
			{
				var file_arr =  v.split(',');							
				var img_code = '<span class="thumb"><img src="'+file_arr[0]+'/'+file_arr[1]+'" width="45" height="35" /></span>';
				$('#selected_file').html(img_code);
				$('#logo').val(file_arr[1]);
				$("#upload-form").dialog('option','hide','explode').dialog('close');
				imageThumbnil();
			}
		});
	
	$('a.close_dialog_btn').click(function() {		 
		$("#upload-form").dialog('option','hide','explode').dialog('close');			
	});
	
	$('a.reset_btn').click(function() {			
		 resetFields();	
		 removeError();	
	});
	
	function resetFields()
	{
		$( "form" )[ 0 ].reset();
		$('#logo').val('<?php echo $this->logo;?>');
		$('span#selected_file').html('<?php echo $logo;?>');
		imageThumbnil();
	}
	
	function removeError()
	{
		$('#actionMessage').attr('class','none');
		$('#actionMessage').html('&nbsp;');
		
		var filename = '';
		var filevalue = '';		
		$.each($('form').serializeArray(), function(i, field) {	
				if(field.name.match(/\[\]$/))
				{
					var filearr = field.name.split('[]');
					filename = filearr[0];					
				}
				else
				{
					filename 	= 	field.name;
				} 			
				$('#'+filename).removeClass('ui-state-error');
				$('#'+filename+'_err').html('');									
		});				
	}
	
	function addError(key,errMsg)
	{
		var err_id = key+'_err';
		var field_name = key;
		$('#'+field_name).addClass('ui-state-error');
		$('#'+err_id).append('<span style="color:#FF0000;font-width:bold;" >'+errMsg+"</span>");
	}
	
	function openLoaderDialog()
	{
		$('#dialog_container').dialog({
					autoOpen: true,
					modal: true,
					show: 'fade',
					resizable: 'false',				
					open: function(event, ui)
						 {
						 	$("#progressbar").progressbar({
								value:100
				
							});							
						  }
				});
	}
	
	function closeLoaderDialog()
	{
		$('#dialog_container').dialog('option','hide','explode').dialog('close');
	}
	
	function getFormData()
	{
		var fieldObj = {};
		var filename = '';
		var filevalue = '';
		$.each($('form').serializeArray(), function(i, field) {	
			if(field.name.match(/\[\]$/))
			{
				/*$("input[name='poll_answer[]']").each(function(id,field) { 				
					poll_answer[id] 		= field.value;
				});
				var filename	= 	field.name.split('[]');
				fieldObj[filename[0]] = poll_answer;
				count++;*/
			}
			else
			{
				filename 	= 	field.name;
				filevalue 	= 	field.value;
				fieldObj[filename] = filevalue;			
			}	
		});
		return fieldObj;
	}
	
	$('a.edit_gateway_btn').click(function() {			
			
			var formData = getFormData();	
			formData.id = '<?php echo $this->id;?>';
			if(formData.active == '1'){ $('[name="active"]').val('1'); $('#active').attr('disabled',true); }
		$.ajax({
				url: "<?php echo $this->url( array('module' => 'Paymentgateway','controller' => 'backendgateway', 'action'     => 'edit' ), 'adminrout',    true) ?>",
			  	type: 'POST',
				beforeSend: function(){						
						removeError();
						openLoaderDialog();				
					 },
			  	data: formData,
				success: function(response){
					//alert(response);					
					var json_arr = eval("("+response+")");					
					closeLoaderDialog();					
					if(json_arr.status == 'ok')
					{
						$('#actionMessage').attr('class','seccMess');
						$('#actionMessage').html(json_arr.msg);											
					}
					else if(json_arr.status == 'errV')
					{
						$('#actionMessage').attr('class','errMess');
						$('#actionMessage').html("<?php echo $this->translator->translator('common_err'); ?>");
												
						for(var i= 0; i <= json_arr.msg.length; i++)
						{
							addError(json_arr.msg[i].key,json_arr.msg[i].value);							
						}
					}
					else
					{
						$('#actionMessage').attr('class','errMess');
						$('#actionMessage').html(json_arr.msg);
					}
				}
		});
	});
	
	/************************************************IMAGE THUMBNIL************************************************/
	function imageThumbnil()
	{	
		$("span.thumb").hover(function() {
			$(this).css({'z-index' : '10'}); /*Add a higher z-index value so this image stays on top*/ 
			$(this).find('img').addClass("hover").stop() /* Add class of "hover", then stop animation queue buildup*/
				.animate({
					marginTop: '-110px', /* The next 4 lines will vertically align this image */ 
					marginLeft: '-110px',
					top: '50%',
					left: '50%',
					width: '174px', /* Set new width */
					height: '174px', /* Set new height */
					padding: '20px'
				}, 200); /* this value of "200" is the speed of how fast/slow this hover animates */
		
			} , function() {
			$(this).css({'z-index' : '0'}); /* Set z-index back to 0 */
			$(this).find('img').removeClass("hover").stop()  /* Remove the "hover" class , then stop animation queue buildup*/
				.animate({
					marginTop: '0', /* Set alignment back to default */
					marginLeft: '0',
					top: '0',
	
					left: '0',
					width: '30px', /* Set width back to default */
					height: '20px', /* Set height back to default */
					padding: '2px'
				}, 400);
		});
	}
});
</script>
<div id="content" style="text-align:left;">
<?php if (!$this->allow()) : ?>
<div class="grid_12 t_a_bottom">
		<?php echo $this->translator->translator('Member_Access_deny_desc'); ?>
	</div>
<?php else : ?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
	<td id="topGo"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	  <tr>
		<td width="100%" valign="top" >
			<form name="formGateway" id="formGateway" method="post" >
			  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
				<tr>
				  <td height="35"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
					  <tr>
						<td width="408" height="65" class="title_1">
							<div style="float:left"><img src="data/adminImages/gatewayImages/payment-edit.gif" /></div>
							<div style="padding-top:23px; float:left">&nbsp; <?php echo $this->translator->translator('gateway_list_page_edit'); ?></div>
						
						</td>
						<td width="367"><table width="360" border="0" align="right" cellpadding="0" cellspacing="0">
							<tr>
							  <td width="120"><div class="extra_btn ui-widget-content-1" align="right"><a href="<?php echo $this->url( array('module' => 'Paymentgateway','controller' => 'backendgateway', 'action'     => 'list'), 'adminrout',    true) ?>" class="back_btn_link"><?php echo $this->translator->translator('common_back'); ?></a></div></td>
							  <td width="120"><div class="extra_btn ui-widget-content-1" align="right"><a href="javascript:  void(0);" class="reset_btn"><?php echo $this->translator->translator('common_reset'); ?></a></div></td>
							  <td width="120" id="button_top_bar"><div class="extra_btn ui-widget-content-1" align="right"><a href="javascript: void(0);" class="edit_gateway_btn"><?php echo $this->translator->translator('gateway_add_page_save'); ?></a></div></td>
							</tr>
						</table></td>
					  </tr>
				  </table></td>
				</tr>
				<tr>
				  <td height="4" bgcolor="#7EAD21"></td>
				</tr>
				<tr>
				  <td height="4"></td>
				</tr>
				<tr>
				  <td id="actionMessage">&nbsp;</td>
				</tr>
				<tr>
				  <td height="4"></td>
				</tr>
				<tr>
				  <td id="generalInfo"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" style="border:1px solid #CCCCCC;">
					<tr>
					  <td class="bar_bg_1">
					  	<table cellpadding="0" cellspacing="0" border="0" width="100%">
							<tr>
								<td style="padding-left:5px;">
					 				 <strong><?php echo $this->translator->translator('gateway_add_page_info'); ?></strong>
								</td>
								<td align="right" style="padding-right:5px;text-align:right;">
									
								</td>
							</tr>
						  </table>
						</td>
					</tr>
					<tr>
					  <td>&nbsp;</td>
					</tr>
					<tr>
					  <td><table width="98%" border="0" align="center" cellpadding="5" cellspacing="0">
						<tr>
						  <td width="25%"   valign="top" style="padding-left:5px;"><?php echo $this->gatewayForm->name->getLabel();  if($this->gatewayForm->name->isRequired()){ ?><span class="required">*</span><?php } ?></td>
						  <td width="75%" valign="top">
						  <?php 					  
							echo $this->gatewayForm->name; 
						  ?>&nbsp;<span id="name_err"></span>					  </td>
						</tr>
						<tr>
						  <td width="25%" valign="top"></td>
						  <td width="75%" valign="top"></td>
						</tr>
						<tr>			
							<td valign="top" style="padding-left:5px;"><?php echo $this->gatewayForm->logo->getLabel();  if($this->gatewayForm->logo->isRequired()){ ?><span class="required">*</span><?php } ?></td>
						 	<td valign="top">	
						  		<table cellpadding="0" cellspacing="0" width="100%" border="0">	
									<tr>
										<td width="24%" valign="top">				
											<div class="extra_btn" align="right" style="width:120px;"><a href="javascript:  void(0);" class="upload_btn"><?php echo $this->translator->translator('common_upload'); ?></a></div>								
									  </td>
										<td width="76%" height="45" valign="top">
											<?php echo $this->gatewayForm->logo; ?>&nbsp;&nbsp;<span id="selected_file"><?php echo $logo;?></span>&nbsp;&nbsp;<span id="logo_err"></span>										</td>
									</tr>
								</table>
							</td>
						</tr>
						<tr>
						  <td width="25%" valign="top"></td>
						  <td width="75%" valign="top"></td>
						</tr>
						<tr>
						  <td valign="top" style="padding-left:5px;"><?php echo $this->gatewayForm->return_url->getLabel();  if($this->gatewayForm->return_url->isRequired()){ ?><span class="required">*</span><?php } ?></td>
						  <td valign="top">						
								<?php echo $this->gatewayForm->return_url; ?>&nbsp;&nbsp;<span id="return_url_err"></span>									
							</td>
						</tr>
						<tr>
						  <td valign="top" style="padding-left:5px;"><?php echo $this->gatewayForm->email->getLabel();  if($this->gatewayForm->email->isRequired()){ ?><span class="required">*</span><?php } ?></td>
						  <td valign="top">						
								<?php echo $this->gatewayForm->email; ?>&nbsp;&nbsp;<span id="email_err"></span>									
							</td>
						</tr>
						<tr>
							<td valign="top" style="padding-left:5px;"><?php echo $this->gatewayForm->lc_locale->getLabel(); if($this->gatewayForm->lc_locale->isRequired()){ ?><span class="required">*</span><?php } ?></td>
							<td valign="top"><?php echo $this->gatewayForm->lc_locale; ?>&nbsp;&nbsp;<span id="lc_locale_err"></span></td>
						</tr>
						<tr>
						  <td valign="top" style="padding-left:5px;"><?php echo $this->gatewayForm->curency->getLabel();  if($this->gatewayForm->curency->isRequired()){ ?><span class="required">*</span><?php } ?></td>
						  <td valign="top">						
								<?php echo $this->gatewayForm->curency; ?>&nbsp;&nbsp;<span id="curency_err"></span>									
							</td>
						</tr>
						<tr>
							<td valign="top" style="padding-left:5px;"><?php echo $this->gatewayForm->test_mode->getLabel(); if($this->gatewayForm->test_mode->isRequired()){ ?><span class="required">*</span><?php } ?></td>
							<td valign="top"><?php echo $this->gatewayForm->test_mode; ?>&nbsp;&nbsp;<span id="test_mode_err"></span></td>
						</tr>
						<tr>
						  <td valign="top" style="padding-left:5px;"><?php echo $this->gatewayForm->active->getLabel();  if($this->gatewayForm->active->isRequired()){ ?><span class="required">*</span><?php } ?></td>
						  <td valign="top">						
								<?php if($this->gatewayForm->active->getValue() == '1'){ $this->gatewayForm->active->setAttrib('disabled',true); } echo $this->gatewayForm->active; if($this->gatewayForm->active->getValue() == '1'){ echo '<input type="hidden" name="active" id="active" value="'.$this->gatewayForm->active->getValue().'"  />'; } ?>&nbsp;&nbsp;<span id="active_err"></span></td>									
						</tr>
						<tr>
							<td valign="top" style="padding-left:5px;"><?php echo $this->gatewayForm->vendor_number->getLabel(); if($this->gatewayForm->vendor_number->isRequired()){ ?><span class="required">*</span><?php } ?></td>
							<td valign="top"><?php echo $this->gatewayForm->vendor_number; ?>&nbsp;&nbsp;<span id="vendor_number_err"></span></td>
						</tr>
						<tr>
							<td valign="top" style="padding-left:5px;"><?php echo $this->gatewayForm->secret_phrase->getLabel(); if($this->gatewayForm->secret_phrase->isRequired()){ ?><span class="required">*</span><?php } ?></td>
							<td valign="top"><?php echo $this->gatewayForm->secret_phrase; ?>&nbsp;&nbsp;<span id="secret_phrase_err"></span></td>
						</tr>
					  </table></td></tr>
				  </table></td></tr>
				 </table>
			</form>
		</td>
	</tr></table></td>
	</tr>
</table>
<div  id="floatingbar">
	<table width="95%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td height="38">
				<?php echo $this->translator->translator('gateway_list_page_edit'); ?>
			</td>
			<td align="right">
				<table width="360" border="0" align="right" cellpadding="0" cellspacing="0">
					<tr>
					  <td width="120"><div class="extra_btn ui-widget-content-1" align="right"><a href="<?php echo $this->url( array('module' => 'Paymentgateway','controller' => 'backendgateway', 'action'     => 'list'), 'adminrout',    true) ?>" class="back_btn_link"><?php echo $this->translator->translator('common_back'); ?></a></div></td>
					  <td width="120"><div class="extra_btn ui-widget-content-1" align="right"><a href="javascript:  void(0);" class="reset_btn"><?php echo $this->translator->translator('common_reset'); ?></a></div></td>
					  <td width="120"><div class="extra_btn ui-widget-content-1" align="right"><a href="javascript: void(0);" class="edit_gateway_btn"><?php echo $this->translator->translator('gateway_add_page_save'); ?></a></div></td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</div>
<?php endif; ?>
<div id="dialog_msg" title="<?php echo $this->translator->translator('common_dialog_msg', $this->translator->translator('gateway_list_page_edit')); ?>">
</div>
<div id="dialog_container" title="<?php echo $this->translator->translator('common_processing_language'); ?>">
	<div id="progressbar" ></div>	
</div>
<div id="upload-form" title="<?php echo $this->translator->translator('gateway_page_dialog_upload'); ?>" align="center">	
	<table width="550" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
		<tr>
		  <td colspan="2" align="center"><iframe id="i-upload-form" src="" width="550" height="400" style="border:0px;" > </iframe></td>
		</tr>
		<tr>
			<td width="449" style="padding-right:5px;padding-bottom:5px;">
				<div class="extra_btn ui-widget-content-1" align="right"><a href="javascript:void(0);" class="select_file_btn"><?php echo $this->translator->translator('gateway_page_insert_upload'); ?></a></div>		  </td>
			<td width="101" style="padding-right:25px;padding-bottom:5px;">
				<div class="extra_btn ui-widget-content-1" align="right"><a href="javascript:void(0);" class="close_dialog_btn"><?php echo $this->translator->translator('common_close'); ?></a></div>		  </td>
		</tr>
	</table>
</div>
</div>